﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PJ.Business;
using Microsoft.Practices.Composite.Events;
using PJ.Business.Inventory;

namespace PJ.Presentation.Inventory
{
    /// <summary>
    /// Inventory item info model
    /// </summary>
    public class InventoryItemInfoModel : ItemViewModel, IInventoryItemInfoModel
    {
        #region Constructor
        /// <summary>
        /// Initialize
        /// </summary>
        public InventoryItemInfoModel()
        {
        }

        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="obj">business object</param>
        /// <param name="service"><see cref="IInventoryItemService"/> service</param>
        public InventoryItemInfoModel(IBusinessObject obj, IInventoryItemService service)
            : base(obj, service)
        {
        }

        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="globalId">object global id</param>
        /// <param name="service"><see cref="IInventoryItemService"/> service</param>
        public InventoryItemInfoModel(string globalId, IInventoryItemService service)
            : base(globalId, service)
        {
        }

        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="view"><see cref="IInventoryItemInfoView"/> view</param>
        /// <param name="aggregator">event aggregator</param>
        /// <param name="service"><see cref="IInventoryItemService"/> service</param>
        [Microsoft.Practices.Unity.InjectionConstructor]
        public InventoryItemInfoModel(IInventoryItemInfoView view, IEventAggregator aggregator, IInventoryItemService service)
            : base(view, aggregator, service)
        {
            EventAggregator.GetEvent<InventoryItemSelectionEvent>().Subscribe(OnSelectionChange);
        }
        #endregion

        #region Public

        ///// <summary>
        ///// GetValues. Sets the businness object properties using the model property values
        ///// </summary>
        ///// <param name="businessObject">business object to update</param>
        //public override IBusinessObject GetValues()
        //{
        //    if (base.GetValues() == null)
        //    {
        //        if (IsStringNull(Name))
        //            return null;
        //    }
        //    BusinessObject.Name = Name;
        //    return BusinessObject;
        //}
        ///// <summary>
        ///// SetValues. Sets the model properties using the businessobject property values
        ///// </summary>
        ///// <param name="businessObject"></param>
        //public override void SetValues(IBusinessObject businessObject)
        //{
        //    base.SetValues(businessObject);
        //    if (businessObject == null)
        //        Name = null;
        //    else
        //        Name = BusinessObject.Name;
        //}


        #endregion

        #region Protected

        //protected override bool ValuesChanged()
        //{
        //    if (base.ValuesChanged())
        //        return true;
        //    else
        //    {
        //        if (IsBusinessObjectNull)
        //        {
        //            if (IsStringNull(this.Name))
        //                return false;
        //            else
        //                return true;
        //        }
        //        return StringEqual(Name, BusinessObject.Name);
        //    }
        //}
        protected new IInventoryItem BusinessObject
        {
            get { return base.BusinessObject as IInventoryItem; }
        }

        #endregion


    }
}
